<template>
  <div class="app-container">
    <!-- 查询区域 -->
    <el-form :model="queryParams" :ref="queryFormRef" inline v-show="showSearch" label-width="auto" @keyup.enter.native="handleQuery">
        <el-form-item label="关键字" prop="keywords" >
          <el-input v-model="queryParams.keywords" placeholder="请输入关键字" clearable />
        </el-form-item>
        <el-form-item label="是否包邮" prop="isFreeFee">
          <lam-dict-select v-model="queryParams.isFreeFee" dictCode="free_fee_type" placeholder="是否包邮" clearable />
        </el-form-item>
        <el-form-item label-width="0px">
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="tool-bar-btn">
      <el-button type="primary" icon="el-icon-plus" @click="handleAdd" v-hasPerms="['mall:transFeeTemplate:add']">新增</el-button>
      <el-button type="success" icon="el-icon-edit" :disabled="single" @click="handleUpdate" v-hasPerms="['mall:transFeeTemplate:edit']">修改</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="multiple" @click="handleDelete" v-hasPerms="['mall:transFeeTemplate:remove']">删除</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </div>

    <!-- 表格区域 -->
    <selected-info :count="selectedRows.length" :onClearSelected="onClearSelected" />
    <el-table :ref="dataTableRef" v-loading="loading" :data="dataList" stripe border @selection-change="onSelectChange"
          :default-sort = "defaultSort" @sort-change="onSortChange" :row-key="rowKey">
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="编号" align="center" prop="id" sortable="custom" width="80"/>
      <el-table-column label="模板名称" align="center" prop="templateName"  width="400" />
      <el-table-column label="是否包邮" align="center" prop="isFreeFeeDictText" width="120"/>
      <el-table-column label="创建人" align="center" prop="createBy"  width="150" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180"/>
      <el-table-column label="更新人" align="center" prop="updateBy"  width="150" />
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180"/>
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="200">
        <template slot-scope="{row}">
          <el-button type="text" icon="el-icon-edit" @click="handleUpdate(row)" v-hasPerms="['mall:transFeeTemplate:edit']">修改</el-button>
          <el-button type="text" icon="el-icon-delete" @click="handleDelete(row)" v-hasPerms="['mall:transFeeTemplate:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="!loading" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"  @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <EditTransFeeTemplate ref="formDialog" @ok="getList" />

  </div>
</template>

<script>
import {httpGet, httpDel} from '@/api';
import { IndexListMixin } from '@/components/mixins/IndexListMixin';
import EditTransFeeTemplate from './edit';

export default {
  name: "TransFeeTemplate",
  mixins:[IndexListMixin],
  components: {
    EditTransFeeTemplate,
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        keywords: null,
        templateNameKey: null,
        shopId: null,
        chargeType: null,
        isFreeFee: null,
        hasFreeCondition: null,
        pageNum: 1,
        pageSize: 10
      },
      url: {
        base: '/mall/transFeeTemplate/',
      	list: '/mall/transFeeTemplate/list'
      }
    };
  },
  created() {
    this.getList();
  },
  mounted(){
  },
  methods: {
    getList() {
      this.loadData(this.url.list);
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.formDialog.toAdd("添加运费模板");
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.selectedRowKeys
      this.$refs.formDialog.toUpdate("修改运费模板", httpGet(this.url.base + id));
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.selectedRowKeys
      this.deleteData(this.url.base, ids);
    },

  }
};
</script>
